package com.easyadmin.modules.stock.service.impl;


import com.easyadmin.common.web.domain.request.PageDomain;
import com.easyadmin.modules.stock.domain.SysStockBlacklistEntity;
import com.easyadmin.modules.stock.domain.SysStockDealRecordEntity;
import com.easyadmin.modules.stock.mapper.SysStockBlacklistDao;
import com.easyadmin.modules.stock.mapper.SysStockDealRecordDao;
import com.easyadmin.modules.stock.service.SysStockDealRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;


@Service("sysStockDealRecordService")
public class SysStockDealRecordServiceImpl extends ServiceImpl<SysStockDealRecordDao, SysStockDealRecordEntity>
        implements SysStockDealRecordService {

    @Autowired
    SysStockDealRecordDao sysStockBlacklistDao;

    @Override
    public PageInfo<SysStockDealRecordEntity> queryPage(SysStockDealRecordEntity sysStockBlacklistEntity, PageDomain pageDomain) {
        PageHelper.startPage(pageDomain.getPage(), pageDomain.getLimit());
        List<SysStockDealRecordEntity> data =sysStockBlacklistDao.selectList(new QueryWrapper<SysStockDealRecordEntity>()
                .lambda().like(StringUtils.isNotBlank(sysStockBlacklistEntity.getStockName()),
                        SysStockDealRecordEntity::getStockName,sysStockBlacklistEntity.getStockName())
                .like(StringUtils.isNotBlank(sysStockBlacklistEntity.getStockCode()),
                        SysStockDealRecordEntity::getStockCode,sysStockBlacklistEntity.getStockCode()));
        return new PageInfo<>(data);
    }

    /**
     * Describe: 根据 id 删除某条数据
     * Param: id
     * Return: Boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean remove(String id) {
        sysStockBlacklistDao.deleteById(Integer.valueOf(id));
        return true;
    }



    /**
     * Describe: 修改用户数据
     * Param: SysUser
     * Return: 操作结果
     */
    @Override
    public boolean update(SysStockDealRecordEntity sysFactorEntity) {
        Integer result = sysStockBlacklistDao.updateById(sysFactorEntity);
        return result > 0;
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchRemove(String[] ids) {
        for(String  id:ids){
            sysStockBlacklistDao.deleteById(id);
        }
        return true;
    }

}